package batframework.mvc.controller;

import javax.servlet.http.Cookie;

import batframework.code.util.Json;
import batframework.mvc.Controller;
import batframework.mvc.Render;
import batframework.mvc.bind.GET;
import batframework.mvc.bind.POST;
import batframework.mvc.bind.Param;
import batframework.mvc.bind.PathParam;
import batframework.mvc.render.FileRender;
import batframework.mvc.render.HtmlRender;
import batframework.mvc.render.RedirectRender;
import batframework.test.UserModel;


public class IndexController extends Controller
{
	
	private IUserModel um =  module(UserModel.class);
	
	@GET
	public void index(String path)
	{
		um.addUser(null);
		redirect("/user/login");
	}
	
	@POST
	public Render index(int id)
	{
		int user_id = param.getInteger("id");
		if(user_id == 0){
			addAttr("id", user_id).addAttr("name", "user");
			return new RedirectRender("/user/login");
		}
		return new FileRender("1.txt");
	}
	
	@GET
	public Render index(@Param("id") long id,@PathParam("name") String name)
	{
		Cookie cookie = getCookie("login");
		return new HtmlRender("dfvdsvdsvdd");
	}
	

	public void addMessage()
	{
		addAttr("data","hello world");
		Json.encode("{hello word}");
		jsonRender();
	}

}
